package 数组.搜索二维矩阵2;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/3/7 16:52
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        int[][]  array = {{1,4,7},{2,5,8},{3,6,9}};
        System.out.println(searchMatrix(array, 5));
    }

    public static boolean searchMatrix(int[][] matrix, int target) {
        int i = matrix.length - 1, j = 0;
        while(i >= 0 && j < matrix[0].length)
        {
            if(matrix[i][j] > target) i--;
            else if(matrix[i][j] < target) j++;
            else return true;
        }
        return false;
    }

}
